// import parseTime, formatTime and set to filter
export { parseTime, formatTime } from '@/utils'

/**
 * Show plural label if time is plural number
 * @param {number} time
 * @param {string} label
 * @return {string}
 */
function pluralize(time, label) {
  if (time === 1) {
    return time + label
  }
  return time + label + 's'
}

/**
 * @param {number} time
 */
export function timeAgo(time) {
  const between = Date.now() / 1000 - Number(time)
  if (between < 3600) {
    return pluralize(~~(between / 60), ' minute')
  } else if (between < 86400) {
    return pluralize(~~(between / 3600), ' hour')
  } else {
    return pluralize(~~(between / 86400), ' day')
  }
}

/**
 * Number formatting
 * like 10000 => 10k
 * @param {number} num
 * @param {number} digits
 */
export function numberFormatter(num, digits) {
  const si = [
    { value: 1E18, symbol: 'E' },
    { value: 1E15, symbol: 'P' },
    { value: 1E12, symbol: 'T' },
    { value: 1E9, symbol: 'G' },
    { value: 1E6, symbol: 'M' },
    { value: 1E3, symbol: 'k' }
  ]
  for (let i = 0; i < si.length; i++) {
    if (num >= si[i].value) {
      return (num / si[i].value).toFixed(digits).replace(/\.0+$|(\.[0-9]*[1-9])0+$/, '$1') + si[i].symbol
    }
  }
  return num.toString()
}

/**
 * 10000 => "10,000"
 * @param {number} num
 */
export function toThousandFilter(num) {
  return (+num || 0).toString().replace(/^-?\d+/g, m => m.replace(/(?=(?!\b)(\d{3})+$)/g, ','))
}

/**
 * Upper case first char
 * @param {String} string
 */
export function uppercaseFirst(string) {
  return string.charAt(0).toUpperCase() + string.slice(1)
}
/**
 *precision指代精确到小数点哪一位，可选0，1，2…
 *symbol则是数字前的符号，一般配置货币符号
 *decimal选项是配置小数点那一位的符号（替换小数点）
 *separator指代分隔符，按照三位数一个分隔符来格式化
 *scale 缩放倍数
 */
export function filterPriceFormat(str) {
  return Number(str || 0).tranFormat(2, -2, true)
}



// 订单状态
export function filterOrderStatus(str) {
  let label = "";
  if (str == 'WAIT_PAY') {
    label = "已下单待支付";
  } else if (str == 'WART_SEND') {
    label = "已支付待派单";
  } else if (str == 'WART_APPOINTMENT') {
    label = "已派单待预约";
  } else if (str == 'WART_SITE') {
    label = "已预约待上门";
  } else if (str == 'WORKING') {
    label = "已上门施工中";
  } else if (str == 'WART_CHECK') {
    label = "已完工待验收";
  } else if (str == 'FINISH') {
    label = "验收完成，订单完结";
  } else if (str == 'REFUND_CLOSE') {
    label = "订单退款关闭";
  } else if (str == 'CANCEL') {
    label = "订单取消";
  } else {
    label = `全部`;
  }
  return label;
}
// 到货情况
export function filterArrivalEnum(str) {
  if (str == 'REACH') {
    return '货物已到客户家'
  } else if (str == 'NOT_REACH') {
    return '货物未到客户家'
  }
  return '--'
}
// 服务类型
export function filterServiceCategoryTypeEnum(str) {
  if (str == 'INSTALLATION') {
    return '安装'
  } else if (str == 'REPAIR') {
    return '维修'
  } else if (str == 'MEASUREMENT') {
    return '测量'
  }
  return '--'
}

// 变更操作类型
export function filterChangeTypeEnum(str) {
  if (str == 'SEND_ORDER') {
    return '派单'
  } else if (str == 'SYNCHRONOUS') {
    return '同步服务商'
  } else if (str == 'APPOINTMENT') {
    return '师傅预约上门时间'
  } else if (str == 'UPDATE_APPOINTMENT') {
    return '师傅修改预约上门时间'
  } else if (str == 'START_WORK') {
    return '师傅上门签到，上传检测照，开始施工'
  } else if (str == 'FINISH_WORK') {
    return '师傅施工完成，上传完工照'
  } else if (str == 'CANCEL_ORDER') {
    return '取消订单'
  } else if (str == 'APPLY_REFUND') {
    return '发起售后'
  } else if (str == 'FINISH_ORDER') {
    return '验收完成'
  } else if (str == 'EVALUATE_ORDER') {
    return '服务评价'
  } else if (str == 'REFUND_CLOSE') {
    return '订单退款关闭'
  }
}



// 流水类型枚举
export function filterSettleType(str) {
  if (str == "INCREASE") {
    return "增加余额"
  } else if (str == "DECREASE") {
    return "扣减余额"
  } else {
    return '--'
  }
}
// 充值类型枚举
export function filterRechargeChangeType(str) {
  if (str == "MEMBER_BALANCE_REFUND_BALANCE") {
    return "退款"
  } else if (str == "MEMBER_BALANCE_RECHARGE") {
    return "充值"
  } else if (str == "WORKER_SECURITY_DEPOSIT_REFUND") {
    return "保证金退款"
  } else {
    return '--'
  }
}


// 充值审核枚举
export function filterRechargeChangeState(str) {
  if (str == "APPROVAL_ING") {
    return "审批中"
  } else if (str == "APPROVAL_REFUSE") {
    return "审批拒绝"
  } else if (str == "APPROVAL_FINISH") {
    return "已完成"
  } else if (str == "APPROVAL_REVOKE") {
    return "已撤回"
  } else {
    return '--'
  }
}



// 师傅流水类型
export function filterRunWaterChangeType(str) {

  if(str == 'CONSUMPTION'){
    return '订单消费'
  }else   if(str == 'EXTRA_SERVICE_CONSUMPTION'){
    return '加价单消费'
  }else   if(str == 'REFUND'){
    return '订单退款'
  }else   if(str == 'ORDER_COMMISSION'){
    return '订单佣金'
  }else   if(str == 'CANCEL'){
    return '退款关闭'
  }else   if(str == 'APPRENTICE_COMMISSION'){
    return '徒弟佣金'
  }else   if(str == 'INDEMNITY'){
    return '售后赔款'
  }else   if(str == 'AFTER_SALES_DEDUCTION'){
    return '售后扣款'
  }else {
    return str
  }
}
  
// 支付方式
export function filterPayMethod(str) {
  if (str == "BALANCE") {
    return "余额支付"
  } else if (str == "ALIPAY") {
    return "支付宝支付"
  } else if (str == 'WECHAT') {
    return "微信支付"
  }
}
